package com.project.class4_11.model.decorate;

public class Test {
    public static void main(String[] args) {
        //点一杯爱尔兰咖啡，加两份牛奶和一份糖
        IProduct p = new IrishCoffee();
        p = new Milk(p);
        p = new Milk(p);
        p = new Sugar(p);

        System.out.println(p.getInfo()+"   价格："+p.getPrice());
    }
}

interface IProduct{
    /**
     * 得到商品描述
     * @return 商品描述
     */
    public String getInfo();

    /**
     * 得到商品价格
     * @return 商品格
     */
    public int getPrice();
}

class IrishCoffee implements IProduct{

    @Override
    public String getInfo() {
        return "爱尔兰咖啡 ";
    }

    @Override
    public int getPrice() {
        return 15;
    }
}

class BlueCoffer implements IProduct{

    @Override
    public String getInfo() {
        return "蓝山咖啡";
    }

    @Override
    public int getPrice() {
        return 12;
    }
}

/**
 * 配料接口
 */
interface Iaccesories extends IProduct{}

class Milk implements Iaccesories{
    /**主料*/
    private IProduct p;
    public Milk(IProduct p){
        this.p = p;
    }

    @Override
    public String getInfo() {
        return p.getInfo()+",加上奶";
    }

    @Override
    public int getPrice() {
        return p.getPrice() + 2;
    }
}

class Sugar implements Iaccesories{
    private IProduct p;
    public Sugar(IProduct p){
        this.p = p;
    }
    @Override
    public String getInfo() {
        return p.getInfo() + "，加上糖";
    }

    @Override
    public int getPrice() {
        return p.getPrice() + 1;
    }
}